#pragma once

#include <linux/spinlock.h>

typedef struct seqcount
{
    unsigned sequence;
} seqcount_t;

typedef struct
{
    seqcount_t seqcount;
    raw_spinlock_t *lock;
} seqcount_raw_spinlock_t;

typedef struct
{
    seqcount_t seqcount;
    spinlock_t *lock;
} seqcount_spinlock_t;

/*
 * Sequential locks (seqlock_t)
 *
 * Sequence counters with an embedded spinlock for writer serialization
 * and non-preemptibility.
 *
 * For more info, see:
 *    - Comments on top of seqcount_t
 *    - Documentation/locking/seqlock.rst
 */
typedef struct
{
    /*
     * Make sure that readers don't starve writers on PREEMPT_RT: use
     * seqcount_spinlock_t instead of seqcount_t. Check __SEQ_LOCK().
     */
    seqcount_spinlock_t seqcount;
    spinlock_t lock;
} seqlock_t;
